package com.sanyang.pda.presenter;

import com.google.gson.Gson;
import com.sanyang.pda.bean.AlreadyDeliveryBean;
import com.sanyang.pda.bean.MovementLogBean;
import com.sanyang.pda.bean.TakeStockListBean;
import com.sanyang.pda.bean.request.AddUnqualifiedRequest;
import com.sanyang.pda.contract.AlreadyDeliveryContract;
import com.sanyang.pda.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.net.bean.BaseRowsAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import java.util.List;

import io.reactivex.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class AlreadyDeliveryPresenter extends BasePresenter<AlreadyDeliveryContract.View> implements AlreadyDeliveryContract.Presenter{

    @Override
    public void toBeProcessedList(int pageNum, int pageSize) {
        NetUtils.geApi().toBeProcessedList(1,10)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseRowsAppEntity<List<AlreadyDeliveryBean>>>() {
                    @Override
                    public void accept(BaseRowsAppEntity<List<AlreadyDeliveryBean>> listBaseRowsAppEntity) throws Exception {
                        getView().setList(listBaseRowsAppEntity.getRows());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {

                    }
                });
    }

    @Override
    public void addUnqualified(AddUnqualifiedRequest addUnqualifiedRequest) {
        RequestBody requestBody = RequestBody.create(MediaType.parse("\"application/json;charset=UTF-8\""), new Gson().toJson(addUnqualifiedRequest));

        NetUtils.geApi().addUnqualified(requestBody)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<TakeStockListBean>>() {
                    @Override
                    public void accept(BaseAppEntity<TakeStockListBean> takeStockListBeanBaseAppEntity) throws Exception {

                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {

                    }
                });
    }

    @Override
    public void scrapConfirmation(String unqualifiedNo, int scrappedNum) {
        NetUtils.geApi().scrapConfirmation(unqualifiedNo, scrappedNum)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<TakeStockListBean>>() {
                    @Override
                    public void accept(BaseAppEntity<TakeStockListBean> takeStockListBeanBaseAppEntity) throws Exception {

                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {

                    }
                });
    }

    @Override
    public void repackageConfirmation() {

    }
}